
module.exports = {
    prefix: "/wx/core/",
    get: {
        "iptest": {
            des: {

            },
            method: function* () {
                var self = this;
                console.log("ipaddess:", self.headers['x-forwarded-for']);
                console.log("ipaddess:", self.socket.remoteAddress);
                self.body = self.headers['x-forwarded-for'] || self.socket.remoteAddress
            }
        },
        "ServiceInit": {
            des: {
                name: "wxServiceConfigInit",
                content: "微信服务创建初始化，这个接口是在公众号中配置微信服务时用来校验微信服务的可用性，不可调用",
                params: [
                    {
                        key: "signature",
                        type: "string",
                    },
                    {
                        key: "timestamp",
                        type: "string|Number"
                    },
                    {
                        key: "nonce",
                        type: "Number|string"
                    }
                ]
            },
            method: function* () {
                var self = this;
                var query = self.request.query;
                printData("正在配置第三方微信服务：", query);
                var result = WX.checkSignature(query.signature, query.timestamp, query.nonce);
                self.body = result ? query.echostr : false;
            }
        },
    },
    post: {
        "ServiceInit": {
            des: {
                name: "wxServiceConfigInit",
                content: "响应微信发过来的内容，处理数据包返回相应的结果,这个接口是响应微信官方做自动化处理的，不可人为调用",
                params: [
                    {
                        key: "signature",
                        type: "string",
                    },
                    {
                        key: "timestamp",
                        type: "string|Number"
                    },
                    {
                        key: "nonce",
                        type: "Number|string"
                    }
                ]
            },
            xmlParser: true,
            method: function* () {
                var self = this;
                var query = self.request.query;
                var xml = self.request.body;
                var json = $.xml2json(xml); //将xml转为json
                // console.log("request:", self.request.body)
                printData("正在配置第三方微信服务：", query);
                // 验证签名，判断请求是否来自微信官方
                var check = WX.checkSignature(query.signature, query.timestamp, query.nonce);
                self.body = check ? $.json2xml(json) : "";
            }
        },
    }
}


